//
//  HYOUHotView.m
//  BestGift
//
//  Created by 温晓宇 on 15/12/30.
//  Copyright © 2015年 dllo. All rights reserved.
//

#import "HYOUHotView.h"
#import "HYOUHotCollectionViewCell.h"

@interface HYOUHotView ()<UICollectionViewDataSource, UICollectionViewDelegate>



@end

@implementation HYOUHotView

-(void)dealloc{
    [_myCollectionView release];
    [_allArray release];
    [super dealloc];
}
/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */
-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubViews];
    }
    return self;
}

-(void)createSubViews{
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    // 设置item大小的
    flowLayout.itemSize = CGSizeMake((WIDTH - 30) / 2, (WIDTH - 30) / 2 + 50);
    // 设置item与屏幕四周的间距
    // 边界距离:上, 左, 下, 右
    flowLayout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
//    [flowLayout release];
    //    // 设置最小行间距
    //    flowLayout.minimumLineSpacing = 10;
    //    // 设置最小列间距
    //    flowLayout.minimumInteritemSpacing = 1;
    self.myCollectionView = [[HYOUBaseCollectionView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT) collectionViewLayout:flowLayout];
    
    [self.myCollectionView registerClass:[HYOUHotCollectionViewCell class] forCellWithReuseIdentifier:@"collection"];
    
//    self.myCollectionView.backgroundColor = RGBA(242, 242, 242, 1);
    self.myCollectionView.delegate = self;
    self.myCollectionView.dataSource = self;
    [self.myCollectionView reloadData];
    [self addSubview:self.myCollectionView];
    [_myCollectionView release];
    
}

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.allArray.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    HYOUHotCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collection" forIndexPath:indexPath];
    cell.model = [self.allArray objectAtIndex:indexPath.row];
    return cell;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    HYOUHotModel *model = [self.allArray objectAtIndex:indexPath.row];
    [self.delegate hotDetail:model.url Image:model.cover_image_url title:model.name];
    NSLog(@"%@",model.url);
}

@end
